package com.example.demo.controller;

import com.example.demo.common.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author Dax
 * @since 15:22  2018/5/17
 */
@RestController
@RequestMapping("/upload")
public class ExcelController {

    @RequestMapping("/reader")
    public Object reader(MultipartFile multipartFile) throws IOException, ExecutionException, InterruptedException {
        InputStream inputStream = multipartFile.getInputStream();
        String fileName = multipartFile.getOriginalFilename();
        boolean is03 = fileName.endsWith("xls");
        long b = System.currentTimeMillis();
//         asy  9122
        ExcelConfig config = ExcelImportRouter.router(RoutingKeyEnum.TOWN_HR.value());
        System.out.println(config);
        Map<String, List<Map<String, String>>> map = ExcelReader.asyncReader(inputStream, is03, config);
         long e = System.currentTimeMillis();
        System.out.println(e - b);
        return map;
    }

}
